package com.ad.pet.app.collect.fragment;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.ad.pet.DaggerMainActivityCompent;
import com.ad.pet.MainActivity;
import com.ad.pet.R;
import com.ad.pet.app.Navigation;
import com.ad.pet.app.collect.CollecContract;
import com.ad.pet.app.collect.CollectActivity;
import com.ad.pet.app.collect.CollectPresenter;
import com.ad.pet.app.collect.adapter.CollectShopAdapter;
import com.ad.pet.common.structure.mvp.BasePresenter;
import com.ad.pet.common.structure.ui.fragment.BaseFragment;
import com.ad.pet.models.remote.account.order.OrderType;
import com.ad.pet.ui.SimpleDividerDecoration;
import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;

/**
 * Created by SEELE on 2018/7/2.
 */

public class ShopCollecFragment extends BaseFragment implements CollecContract.View {
    //    ProgressDialog mProgressDialog;
    @Inject
    CollectPresenter mCollectPresenter;
    @BindView(R.id.recycler_shop)
    RecyclerView mRecyclerShop;
    private CollectShopAdapter mCollectShopAdapter;


    @Override
    protected void initData() {
//        mProgressDialog = DialogUtil.createProgressDialog(getActivity(), getString(R.string.loading));
        mCollectPresenter.onCreate(this);
    }

    @Override
    protected void initEvents() {
        mCollectShopAdapter.setOnDelLinstener(new CollectShopAdapter.OnDelLinstener() {
            @Override
            public void del(int position) {
            }
        });

        mCollectShopAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {

                    Navigation.goCommonWebView((getActivity()), getString(R.string.shop_detail), mCollectShopAdapter.getData().get(position).getStoreurl(), false, MainActivity.REQUEST_GO_MALL);

            }
        });
    }

    @Override
    protected void initViews() {
        mRecyclerShop.addItemDecoration(new SimpleDividerDecoration(getContext(), 16, R.color.bg_color));
        mRecyclerShop.setLayoutManager(new LinearLayoutManager(getContext()));
        mCollectShopAdapter = new CollectShopAdapter(null);
        mRecyclerShop.setAdapter(mCollectShopAdapter);
    }

    @Override
    public void initInjector() {
        DaggerMainActivityCompent.builder().applicationComponent(((CollectActivity) getActivity()).getApplicationComponent())

                .activityModule(((CollectActivity) getActivity()).getActivityModule()).build().inject(this);
    }

    @Override
    public int initContentView() {
        return R.layout.fragment_shop_collection;
    }

    @Override
    protected BasePresenter getPresenter() {
        return mCollectPresenter;
    }

    @Override
    public void showLoading() {
//        mProgressDialog.show();
    }

    @Override
    public void hideLoading() {
//        mProgressDialog.dismiss();
    }

    @Override
    public void error(String msg) {

    }

    @Override
    public void error(int code, String msg) {

    }


    @Override
    public void getCollectGoodsSuccess(List<OrderType> allGood) {

    }
}
